
#include "stdafx.h"
#include "Parameter.h"




DWORD dwLevel;			// 2 - 40;		dwLevel= Difficult Level + Increase Level
DWORD dwPWM;
// dwPWM = CalcPWM( dwLevel );
DWORD CalcPWM ( DWORD dwL ) {
	static DWORD pdwBarToPWMTable[] = {                                                       		
  	0, 2, 5, 9, 12, 15, 17, 20, 22, 25, 27, 29, 31, 33, 35, 37,	39, 41, 43, 45, 
  	47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77,	79, 81, 83, 85
  };
	if ( dwL < 1 )
		dwL = 1;
	dwL--;
	if ( dwL > 39 )
		dwL = 39;
	return ( pdwBarToPWMTable[dwL] );
}

DWORD dwCount;
//	dwCount = GenReadCount();				0xRRRRLLLL:	RRRR(Right hand), LLLL(Left hand)
DWORD dwRPM;
//	dwRPM = GenReadRPM();



//  dwR=RPM, dwP=PWM
double WATTcalc( DWORD dwR, DWORD dwP )		
{			
	static DWORD pdwPWMTable[] = {                                                       		
  	0, 5, 10, 15, 20, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85   
  };                                                                                   
  static DWORD pdwRPMTable[] = {                                                       
  	30, 40, 50, 60, 70, 80, 90, 100, 110, 120                                          
  };                                                                                   
  static double pdwWATTTable[][10] = {                                                       
  	{ 8.1, 11.6, 14.0, 18.6, 21.0, 24.8, 31.5, 42, 48.4, 55.2 },
		{ 10.2, 16, 20, 27.6, 34.3, 42.4, 58.5, 72, 84.7, 101 },
		{ 13.2, 20.4, 28, 38.4, 51.8, 71.2, 87.3, 107, 131, 156 },
		{ 16.5, 26.4, 40, 49.2, 69.3, 92, 122, 155, 168, 212 },
		{ 20.7, 33.6, 48.5, 72, 95.2, 123, 158, 185, 235, 275 },
		{ 25.8, 41.6, 62, 89.4, 120, 154, 189, 235, 267, 336 },
		{ 29.7, 48.8, 71.5, 106, 135, 182, 221, 281, 292, 390 },
		{ 34.5, 56.4, 85, 123, 149, 214, 266, 332, 330, 458 },
		{ 38.7, 65.2, 92.5, 146, 169, 214, 293, 360, 370, 493 },
		{ 42.9, 73.2, 107, 163, 188, 240, 300, 384, 409, 480 },
		{ 48.9, 76.8, 122, 172, 209, 264, 319, 380, 451, 512 },
		{ 52.2, 81.2, 134, 195, 228, 320, 356, 415, 543, 566 },
		{ 59.7, 89.2, 134, 212, 260, 336, 384, 440, 591, 608 },
		{ 66.6, 98, 141, 229, 281, 354, 485, 488, 630, 649 },
		{ 75.3, 110, 151, 249, 299, 394, 476, 510, 688, 708 },
		{ 82.5, 115, 165, 256, 330, 427, 513, 603, 721, 816 },
		{ 96.3, 133, 171, 289, 343, 427, 539, 638, 762, 864 },
		{ 90.6, 147, 190, 296, 372, 470, 567, 678, 789, 884 },
		{ 92.1, 158, 206, 308, 400, 499, 594, 689, 823, 918 },
		{ 95.4, 172, 222, 324, 417, 486, 617, 718, 831, 961 },
		{ 96, 195, 256, 348, 427, 520, 642, 743, 863, 955 }
	};
                                                                                   
  int iRow, iCol;
                                                                                       
	if (dwR < 5)     //	??????????????
  	return 0;
  if (dwP > 85)                                                                        
  	dwP = 85;  
  int i=0;
  for( i=0; dwP > pdwPWMTable[i]; i++ )                                            
  	;                                                                                  
  if( i == 0 )                                                                         
  	iRow = i;                                                                          
  else                                                                                 
  	iRow = ((pdwPWMTable[i] - dwP) > (dwP - pdwPWMTable[i-1])) ? (i-1) : i;            
  	                                                                                   
  if (dwR > 120)                                                                       
  	dwR = 120;                                                                         
  if (dwR < 30)                                                                        
  	dwR = 30;                                                                          
  for( int i=0; dwR > pdwRPMTable[i]; i++ )                                            
  	;                                                                                  
  if( i == 0 )                                                                         
  	iCol = i;                                                                          
  else                                                                                 
  	iCol = ((pdwRPMTable[i] - dwR) > (dwR - pdwRPMTable[i-1])) ? (i-1) : i;

  return pdwWATTTable[iRow][iCol];

}	                                                                                   
  	                                                                                   